package com.crm.service.impl.memberManager;

import com.crm.dao.mapper.customMapper.memberManagerCustomMapper.MembershipCardCustomMapper;
import com.crm.dao.mapper.memberManager.CustomerMemberCardMapper;
import com.crm.dao.mapper.memberManager.CustomerMemberCardOldMapper;
import com.crm.model.entity.memberManager.CustomerMemberCard;
import com.crm.model.entity.memberManager.CustomerMemberCardExample;
import com.crm.model.entity.memberManager.CustomerMemberCardOld;
import com.crm.model.entity.memberManager.CustomerMemberCardOldExample;
import com.crm.model.entity.returnMoney.ReturnMoney;
import com.crm.model.qo.memberManager.MemberShipCardQO;
import com.crm.model.vo.memberManager.MemberCardOldVO;
import com.crm.model.vo.memberManager.MemberShipCardListVO;
import com.crm.service.memberManager.MemberCardDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/4/8 14:14
 */
@Service
public class MemberCardDbServiceImpl implements MemberCardDbService {

    @Autowired
    private MembershipCardCustomMapper membershipCardCustomMapper;

    @Autowired
    private CustomerMemberCardMapper customerMemberCardMapper;

    @Autowired
    private CustomerMemberCardOldMapper customerMemberCardOldMapper;

    /***
     * @Description: 查询会员卡列表
     * @Param: 查询条件
     * @Author: luojie
     * @Date: 2021/4/8 14:58
     */
    @Override
    public List<MemberShipCardListVO> selectMemberShipCardList(MemberShipCardQO memberShipCardQO) {
        List<MemberShipCardListVO> memberShipCardListVOList = membershipCardCustomMapper.selectMemberShipCardList(memberShipCardQO);
        return memberShipCardListVOList;
    }

    /**
     * 从会员卡表随机取一个未发放的会员卡
     * @return
     */
    @Override
    public CustomerMemberCard selectMemberShipCard() {
        return membershipCardCustomMapper.selectMemberShipCard();
    }

    /**
     * 修改会员卡信息
     * @param customerMemberCard 会员卡实体
     * @return
     */
    @Override
    public Boolean updateCustomerMemberCard(CustomerMemberCard customerMemberCard) {
        Boolean result = false;
        int num = customerMemberCardMapper.updateByPrimaryKeySelective(customerMemberCard);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    @Override
    public Boolean insertMemberCard(CustomerMemberCard customerMemberCard) {
        Boolean result = false;
        int num = customerMemberCardMapper.insertSelective(customerMemberCard);
        if(num>0){
            result = true;
        }
        return result;
    }

    @Override
    public CustomerMemberCard selectMemberShipCardIsRepeat(String memberCardNumber) {
        CustomerMemberCardExample customerMemberCardExample = new CustomerMemberCardExample();
        CustomerMemberCardExample.Criteria criteria = customerMemberCardExample.createCriteria();
        criteria.andMemberCardNumberEqualTo(memberCardNumber);
        List<CustomerMemberCard> customerMemberCards = customerMemberCardMapper.selectByExample(customerMemberCardExample);
        if(customerMemberCards.size()>0){
            return customerMemberCards.get(0);
        }else {
            return null;
        }
    }

    /***
     * @Description: 查询旧系统会员卡列表
     * @Param:
     * @Author: luojie
     * @Date: 2021/4/8 13:41
     */
    @Override
    public List<MemberCardOldVO> selectMemberCardOldList(MemberShipCardQO memberShipCardQO) {
        List<MemberCardOldVO> list = membershipCardCustomMapper.selectMemberCardOldList(memberShipCardQO);
        return list;
    }

    /***
     * @Description: 查询旧系统公司名称
     * @Param:
     * @Author: luojie
     * @Date: 2021/4/8 13:41
     */
    @Override
    public List<MemberCardOldVO> getCompanyList() {
        List<MemberCardOldVO> list = membershipCardCustomMapper.getCompanyList();
        return list;
    }

    /**
     * 查询会员卡开始时间和结束时间为空的
     * @return
     */
    @Override
    public List<MemberCardOldVO> selectCardDate() {
        return membershipCardCustomMapper.selectCardDate();
    }

}
